<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>let</title>
	</head>
	<body>
	</body>

	<script>
		// var的申明往往会越域
		//let申明的变量具有严格的局部作用域
		// {
		// 	var a = 1;
		// 	let b = 2;

		// }
		// console.log(a);
		// console.log(b);

		/**
		 * 		输出结果:
		 *	 let.html:19 Uncaught ReferenceError: b is not defined
		 *	    at let.html:19
		 */
		/**************************************/
		// var 可以声明多次
		// 但是`let` 只能声明一次
		// var m = 1;
		// var m = 2;
		// let n = 1;
		// let n = 2;
		/**
		 * 输出结果:
		 * Uncaught SyntaxError: Identifier 'n' has already been declared
		 */

		/************************************/
		// var 会变量提升,let不会存在变量提升
		console.log(x);
		var x = 10;

		console.log(y);
		let y = 10;
		/**
		 * 输出结果:
		 * undefined
          let.html:43 Uncaught ReferenceError: Cannot access 'y' before initialization
           at let.html:43
		 */
		
	    /***********************************/
		// const 声明后不允许改变,一旦声明必须初始化,否则会报错
		const a = 1;
		a = 3; 
		/**
		 * 输出结果:
		 *  let.html:55 Uncaught TypeError: Assignment to constant variable.
           at let.html:55
		 */
	</script>
</html>
